import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 常量路由表，不用登录即可看到
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  },

]
// 异步路由表，只有登录之后才可看到,所有的异步路由表
 export const allAsyncRoutes=[
  {
    path: '/production',
    component: Layout,
    redirect: '/production/trademark/list',
    name: 'Product',
    meta: { title: '商品管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/trademark/list',
        name: 'Trademark',
        component: () => import('@/views/production/trademark'),
        meta: { title: '品牌管理', icon: 'el-icon-link' }
      },
      {
        path: '/attr/list',
        name: 'Attr',
        component: () => import('@/views/production/attr'),
        meta: { title: '属性管理', icon: 'el-icon-watermelon' }
      },
      {
        path: '/sku/list',
        name: 'Sku',
        component: () => import('@/views/production/sku'),
        meta: { title: 'Sku管理', icon: 'el-icon-goblet-square-full' }
      },
      {
        path: '/spu/list',
        name: 'Spu',
        component: () => import('@/views/production/spu'),
        meta: { title: 'Spu管理', icon: 'el-icon-cold-drink' }
      }
    ]
  },
  {
    path: '/Acl',
    component: Layout,
    redirect: '/acl/user/list',
    name: 'Acl',
    meta: { title: '权限管理', icon: 'password' },
    children: [
      {
        path: '/user/list',
        name: 'User',
        component: () => import('@/views/acl/user'),
        meta: { title: '用户管理', icon: 'el-icon-user' }
      },
      {
        path: '/role/list',
        name: 'Role',
        component: () => import('@/views/acl/role'),
        meta: { title: '角色管理', icon: 'el-icon-setting' }
      },
      {
        path: '/roleAuth/list',
        name: 'RoleAuth',
        component: () => import('@/views/acl/roleAuth'),
        meta: { title: '角色授权', icon: 'el-icon-s-check' },
        hidden: true
      },
      {
        path: '/permission/list',
        name: 'Permission',
        component: () => import('@/views/acl/permission'),
        meta: { title: '菜单管理', icon: 'el-icon-s-order' }
      }
    ]
  }
]
export const anyRoute={
  path:'*',redirect:'/404',hidden:true
}


const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
